package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("images")
public class ImageController {
    @PostMapping
    public Map upload(MultipartFile file){
        HashMap<Object, Object> map = new HashMap<>();
        try {
            String url = UploadUtil.upload(file, UploadUtil.PATH + "/upload");
            //操作成功的状态
            map.put("status",1);//判断操作成功还是失败
            map.put("url",url);//成功就存入图片回显的路径("/upload/"+文件名)
        } catch (Exception e) {
            e.printStackTrace();
           map.put("status",0);
           map.put("msg",e.getMessage());//失败存入异常信息
        }
        return map;
    }
}
